package LeetCode;

import java.util.ArrayList;

public class LC_230_KthSmallestElementinaBST {

    public static void main(String[] args) {

    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class Solution {
        ArrayList<Integer> al = new ArrayList<>();

        public int kthSmallest(TreeNode root, int k) {
            ListAll(root);
            return al.get(k - 1);
        }

        void ListAll(TreeNode root) {
            if (root != null) {
                ListAll(root.left);
                al.add(root.val);
                ListAll(root.right);
            }
        }

    }
}